<?php
/**
 * PHP Daycare
 * This file is the administrator panel. The plan is for all admin operations to take place here
 * @author Jason Butz
 * @version 0.0
 * @package PHPDaycare
 */

include_once("functions.php");
include_once("config.php");
session_start();
// Our user must be logged in to view things, otherwise they get a login screen!
if($session->isloggedin())
{
	// The user is logged in. This is good
	// But are they an admin?
	$sql = "SELECT * FROM `worker` WHERE `username` = '".$_SESSION['user']."' AND `administrator` = 1;";
	$r = $db->query($sql);
	if(!mysql_fetch_row($r))
	{
		$log->loginFailA($_SESSION['user']);
		// They may be logged in, but they are NOT an admin
		// Show an error message on the main page with a menu
		$msg = "Error: You are not an administrator. 
			To access the administrator panel please logout and 
			log back in as a user with administrative privileges.";
		$temp->displayCont($msg, TRUE);
	}
	else
	{
		$log->adminLogin($_SESSION['user']);
		$temp->displayAdmin('adminMain'); // Display an admin screen. The template given in the default page.
	}
}
else
{
	//The user is not logged in, so show the login template
	$temp->display('login', FALSE); // Display a login prompt without a menu
}
?>
